package outoforder.leetcode;

import org.junit.Test;

/**
 * @author shhjiang_001
 * @create 2020-07-01 15:16
 */
public class Solution121 {
    public int maxProfit(int[] prices) {
        int[][] dp = new int[prices.length][2];
        for (int i = 0; i < prices.length; i++) {
            if (i == 0){
                dp[i][0] = 0;
                dp[i][1] = -prices[0];
                continue;
            }
            dp[i][0] = Math.max(dp[i-1][0],dp[i-1][1]+prices[i]);
            dp[i][1] = Math.max(dp[i-1][1],0-prices[i]);
        }
        return dp[prices.length-1][0];
    }
    @Test
    public void  test(){
        System.out.println(maxProfit(new int[]{7, 1, 5, 3, 6, 4}));
    }

}
